﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
/*
 http://msmvps.com/blogs/paulomorgado/pages/the-cost-of-client-side-redirects-in-asp-net-and-using-page-modules-.aspx
 * 
 */
namespace SAHM
{
    public class AnalyticsModule:IHttpModule
    {
        
        #region IHttpModule Members

        public void Dispose()
        {
        }

        public void Init(HttpApplication context)
        {
            if (context != null)
            {
                //Occurs when ASP.NET has completed executing all request event handlers and the request state data has been stored.
                context.PostReleaseRequestState += new EventHandler(context_PostReleaseRequestState);
            }
        }

        void context_PostReleaseRequestState(object sender, EventArgs e)
        {
            HttpApplication context = sender as HttpApplication;
            if (context != null && context.Response != null)
            {
                // limit to the html pages, otherwise we will be in troubel when requesting other stuff like ressources
                if (string.Compare(context.Response.ContentType, "text/html",true) == 0)
                {
                    context.Response.Filter = new AnalyticsFilter(context.Response.Filter);
                }
            }
        }

        #endregion
    }
}
